// Created by WXX on 2022/2/1 19:36
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * 执行用时：0 ms, 在所有 C++ 提交中击败了100.00%的用户
 * 内存消耗：5.9 MB, 在所有 C++ 提交中击败了88.89%的用户
 */
class Solution {
public:
    string longestNiceSubstring(string s) {

        string res;
        for (int i = 0; i < s.size(); i++) {
            int a = 0, b = 0;
            for (int j = i; j < s.size(); j++) {
                if (s[j] >= 'a' && s[j] <= 'z') a |= (1 << (s[j] - 'a'));
                else b |= (1 << (s[j] - 'A'));

                if (a == b && (s.empty() || j - i + 1 > res.size())) res = s.substr(i, j - i + 1);
            }
        }
        return res;
    }
};

int main() {

    cout << Solution().longestNiceSubstring("YazaAay") << endl;

    return 0;
}
